package leetcode.code0979;

import leetcode.helper.H;
import leetcode.helper.tree.TreeArray;
import leetcode.helper.tree.TreeNode;
import leetcode.IDebug;

public class Solution implements IDebug {
	


	int ans;

	public int distributeCoins(TreeNode root) {
		ans = 0;
		this.find(root);
		return ans;
	}
	
	private int find(TreeNode root) {
		if (root == null) {
			return 0;
		}
		int cur = root.val;
		int left = this.find(root.left);
		int right = this.find(root.right);
		int sum = cur + left + right - 1;
		ans += Math.abs(sum);
		return sum;
	}


	@Override
	public void debug4() {
		H.compare(2, this.distributeCoins(TreeArray.array2tree(H.str2array4("[3,0,0]"))));
		

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
